package com.lantosec.hmrp.modules.eval.controller.app;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lantosec.hmrp.core.kit.PageVO;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import com.lantosec.hmrp.core.mvc.BaseController;
import com.lantosec.hmrp.modules.eval.entity.EvalPlanTarget;
import com.lantosec.hmrp.modules.eval.service.IEvalTaskService;
import com.lantosec.hmrp.modules.eval.vo.EvalDetailedVO;
import com.lantosec.hmrp.modules.eval.vo.EvalPlanVO;
import com.lantosec.hmrp.modules.eval.vo.EvalTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * 考评任务 控制器
 *
 * @author AutoCode
 * @since 2020-03-30
 */
@Api(value = "考评任务控制器APP端", tags = "考评任务控制器APP端")
@RestController
@RequestMapping("/eval/app/task")
@Log4j2
public class EvalTaskAppController extends BaseController {
    @Autowired
    private IEvalTaskService service;

    @GetMapping("getNotFinishedTask")
    @ApiOperation(value = "查询未完成的考评任务")
    public Result<Page<EvalPlanVO>> getNotFinishedTask(@ApiParam(value = "分页对象", required = true) PageVO<EvalPlanVO> page,
               @ApiParam(name ="开始时间" ,value = "startDate") @RequestParam(name = "startDate",required = false) String startDate,
               @ApiParam(name ="结束时间" ,value = "endDate") @RequestParam(name = "endDate",required = false) String endDate,
               @ApiParam(name ="计划名称" ,value = "evalPlanName") @RequestParam(name = "evalPlanName",required = false) String evalPlanName,
               @ApiParam(name ="考评周期" ,value = "evalPlanCycle") @RequestParam(name = "evalPlanCycle",required = false) Integer evalPlanCycle,
               @ApiParam(name ="计划类型" ,value = "evalPlanType") @RequestParam(name = "evalPlanType",required = false) Integer evalPlanType,
               @ApiParam(name ="考评形式" ,value = "evalMode") @RequestParam(name = "evalMode",required = false) Integer evalMode,
               @ApiParam(name ="计划状态" ,value = "state") @RequestParam(name = "state",required = false) Integer state,
               @ApiParam(name ="权限编码,1个人2科室3全院" ,value = "permissionsType") @RequestParam(name = "permissionsType",required = false) Integer permissionsType){
        String userId = getUserId();
        String deptId = getDeptId();
        service.getNotFinishedTask(page,startDate,endDate,evalPlanName,evalPlanCycle,
                evalPlanType,evalMode,state,permissionsType,userId,deptId);
        return Result.ok(page);
    }

    @GetMapping("getFinishedTask")
    @ApiOperation(value = "查询已完成的考评任务")
    public Result<Page<EvalPlanVO>> getFinishedTask(@ApiParam(value = "分页对象", required = true) PageVO<EvalPlanVO> page,
            @ApiParam(name ="开始时间" ,value = "startDate") @RequestParam(name = "startDate",required = false) String startDate,
            @ApiParam(name ="结束时间" ,value = "endDate") @RequestParam(name = "endDate",required = false) String endDate,
            @ApiParam(name ="计划名称" ,value = "evalPlanName") @RequestParam(name = "evalPlanName",required = false) String evalPlanName,
            @ApiParam(name ="考评周期" ,value = "evalPlanCycle") @RequestParam(name = "evalPlanCycle",required = false) Integer evalPlanCycle,
            @ApiParam(name ="计划类型" ,value = "evalPlanType") @RequestParam(name = "evalPlanType",required = false) Integer evalPlanType,
            @ApiParam(name ="考评形式" ,value = "evalMode") @RequestParam(name = "evalMode",required = false) Integer evalMode,
            @ApiParam(name ="权限编码,1个人2科室3全院" ,value = "permissionsType") @RequestParam(name = "permissionsType",required = false) Integer permissionsType){
        String userId = getUserId();
        String deptId = getDeptId();
        service.getFinishedTask(page,startDate,endDate,evalPlanName,
                evalPlanCycle,evalPlanType,evalMode,permissionsType,userId,deptId);
        return Result.ok(page);
    }

    @GetMapping("get")
    @ApiOperation(value = "开始考评下一步")
    public Result<List<EvalTypeVO>> get(@ApiParam(value = "evalTaskId", required = true) @RequestParam(name="evalTaskId") Integer evalTaskId,
                                  @ApiParam(value = "planTargetId", required = true) @RequestParam(name="planTargetId") Integer planTargetId){
        List<EvalTypeVO> evalTypeVOList = service.get(evalTaskId,planTargetId);
        return Result.ok(evalTypeVOList);
    }

    @GetMapping("getParm")
    @ApiOperation(value = "开始考评详情")
    public Result<List<EvalTypeVO>> getParm(@ApiParam(value = "evalTaskId", required = true) @RequestParam(name="evalTaskId") Integer evalTaskId,
                                            @ApiParam(value = "evalDetailedId", required = true) @RequestParam(name="evalDetailedId") Integer evalDetailedId){
        List<EvalTypeVO> evalTypeVOList = service.getParm(evalTaskId,evalDetailedId);
        return Result.ok(evalTypeVOList);
    }

    @GetMapping("startEval/{evalPlanId}")
    @ApiOperation(value = "开始考评")
    public Result<List<EvalPlanTarget>> startEval(@ApiParam(value = "evalPlanId", required = true) @PathVariable(name="evalPlanId") Integer evalPlanId){
        List<EvalPlanTarget> evalDetailedList = service.startEval(evalPlanId);
        return Result.ok(evalDetailedList);
    }

    @GetMapping("getFinishedTaskParm/{evalPlanId}")
    @ApiOperation(value = "查询已完成考评任务详情")
    public Result<List<EvalPlanTarget>> getFinishedTaskParm(@ApiParam(value = "evalPlanId", required = true) @PathVariable(name="evalPlanId") Integer evalPlanId){
        List<EvalPlanTarget> evalPlanTargetList = service.getFinishedTaskParm(evalPlanId);
        return Result.ok(evalPlanTargetList);
    }

    @PutMapping("update")
    @ControllerLog(name = "考评任务提交", type = LogType.update)
    @ApiOperation(value = "开始考评任务提交")
    public Result<Void> update(@ApiParam(value = "考评任务明细ID",required = true) @RequestBody EvalDetailedVO evalDetailedVO){
        Integer evalDetailedId = evalDetailedVO.getEvalDetailedId();
        Integer state = evalDetailedVO.getState();
        service.updateEvalTask(evalDetailedId,state);
        return Result.ok();
    }
}
